package edu.whut.mall.admin.controller;

import edu.whut.mall.admin.service.IPayInfoService;
import edu.whut.mall.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;

/**
 * @author Wayne
 * @projectName d9lab-mall
 * @description: 商家支付信息控制器
 * @date 2020/11/30 19:24
 */
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/groupBuy")
@RestController
@Api(value="支付管理器",tags = {"支付管理器"})
public class RestPayInfoController {
    private final IPayInfoService payInfoService;

    @ApiOperation("根据状态查询退款请求")
    @PostMapping(value="/listRefundRequestVoByStatus")
    public CommonResult listRefundRequestVoByStatus(@RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                                    @RequestParam(value="size",defaultValue ="10") Integer size,
                                                    @RequestParam(required = false) Integer status){
        return CommonResult.success(payInfoService.listRefundRequestVoByStatus(pageNum, size, status), "获取成功");
    }

    @ApiOperation("同意退款")
    @PostMapping(value="/confirmRefund")
    public CommonResult confirmRefund(@RequestParam String orderNo) throws NoSuchAlgorithmException {
        return payInfoService.refundProcessing(orderNo);
    }

    @ApiOperation("拒绝退款")
    @PostMapping(value="/refuseRefund")
    public CommonResult refuseRefund(@RequestParam String orderNo) {
        payInfoService.refuseRefund(orderNo);
        return CommonResult.success("拒绝退款成功");
    }
}
